package com.example.demo.controller;

import com.example.demo.entity.ResponseResult;
import com.example.demo.entity.Supplier;
import com.example.demo.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/supplier")
@Api(tags = "供应商接口")
public class SupplierController {

    @Resource
    private SupplierService supplierService;


    @GetMapping
    @ApiOperation(value = "查询全部供应商")
    public ResponseResult getList(){
        return supplierService.getList();
    }

    @GetMapping("/getByName/{name}")
    @ApiOperation(value = "根据名称查询供应商")
    public ResponseResult getByName(@PathParam(value = "name") String name){
        return supplierService.getByName(name);
    }

    @PostMapping
    @ApiOperation(value = "新增供应商信息")
    public ResponseResult saveSupplier(@RequestBody Supplier supplier){
        return supplierService.saveSupplier(supplier);
    }

    @PutMapping
    @ApiOperation(value = "修改供应商信息")
    public ResponseResult updateSupplier(@RequestBody Supplier supplier){
        return supplierService.updateSupplier(supplier);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation(value = "根据id删除")
    public ResponseResult deleteById(@RequestParam String id){
        return supplierService.deleteById(id);
    }

    @DeleteMapping("/deleteByName")
    @ApiOperation(value = "根据名称删除")
    public ResponseResult deleteByName(@RequestParam String name){
        return supplierService.deleteByName(name);
    }
}
